//
//  TFSegmentView.h
//  TFFoundation
//
//  Created by TFAppleWork-Summer on 2017/8/10.
//  Copyright © 2017年 TFAppleWork-Summer. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "TFSegmentViewItemCellProtocol.h"


/**
 TFSegmentView,分割view
 */
@interface TFSegmentView : UIView

/**
 初始化方法

 @param frame frame
 @param itemsArray item字符串数组
 @return TFSegmentView
 */
- (nonnull instancetype)initWithFrame:(CGRect)frame itemsArray:(nonnull NSArray<NSString *> *)itemsArray;

/**
 collectionView
 */
@property (nonatomic, strong, nonnull) UICollectionView *collectionView;

/**
 item 字体大小，默认14
 */
@property (nonatomic, strong, nonnull) UIFont *itemFont;

/**
 item字符串数组
 */
@property (nonatomic, strong, nonnull) NSArray<NSString *> *itemsArray;

/**
 当前选中的item的索引
 */
@property (nonatomic, assign) NSInteger selectedItemIndex;

/**
 修饰view，可以是一条线，也可以是一个背景等等，默认为一条高度为2pt，宽度和item宽度相同的线
 */
@property (nonatomic, strong, nonnull) UIView *decorateView;

/**
 注册自定义cell，需为UICollectionViewCell服从TFSegmentViewItemCellProtocol，若实现此block，则不会注册默认cell--TFSegmentViewItemCell
 */
@property (nonatomic, copy, nullable) void(^registerCustomItemCellBlock)(UICollectionView * __nonnull collectionView);

/**
 返回自定义的cell，需要先通过registerCustomItemCellBlock注册才可以
 */
@property (nonatomic, copy, nullable) __kindof UICollectionViewCell<TFSegmentViewItemCellProtocol> * _Nonnull (^customItemCellForItemBlock)(UICollectionView * __nonnull collectionView,NSString * __nonnull item, NSInteger index);

/**
 当cell reload的时候调用
 */
@property (nonatomic, copy, nullable) void(^itemCellReloadBlock)(__kindof UICollectionViewCell<TFSegmentViewItemCellProtocol> * __nonnull cell, NSString * __nonnull item, NSInteger index);

/**
 选中某个cell时调用
 */
@property (nonatomic, copy, nullable) void(^itemCellDidSelectBlock)(__kindof UICollectionViewCell<TFSegmentViewItemCellProtocol> * __nonnull cell, NSString * __nonnull item, NSInteger index);

/**
 取消选中某个cell时调用
 */
@property (nonatomic, copy, nullable) void (^itemCellDidDeselectBlock)(__kindof UICollectionViewCell<TFSegmentViewItemCellProtocol> * __nonnull cell, NSString * __nonnull item, NSInteger index);

/**
 返回自定义的装饰view的frame
 */
@property (nonatomic, copy, nullable) CGRect (^customDecorateViewFrameBlock)(UIView * __nonnull decorateView,CGRect itemCellFrame,NSInteger index, CGFloat percent);

/**
 每个item间的space，默认20.0
 */
@property (nonatomic, assign) CGFloat itemSpace;

/**
 item最左边的间距，默认20.0
 */
@property (nonatomic, assign) CGFloat itemLeading;

/**
 item最右边的间距，默认20.0
 */
@property (nonatomic, assign) CGFloat itemTrailing;

/**
 真正显示的space
 */
@property (nonatomic, assign, readonly) CGFloat itemShowSpace;

/**
 真正显示的最左边间距
 */
@property (nonatomic, assign, readonly) CGFloat itemShowLeading;

/**
 真正显示的最右边的间距
 */
@property (nonatomic, assign, readonly) CGFloat itemShowTrailing;

/**
 获取对应index和百分比的装饰view的frame，子类可重写此方法返回对应的frame

 @param index 索引
 @param percent 百分比
 @param animationDurationBlock 返回动画时长的block
 @return CGRect
 */
- (CGRect)decorateViewFrameForIndex:(NSInteger)index withPercent:(CGFloat)percent animationDurationBlock:(void(^ __nullable)(CGFloat duration))animationDurationBlock;

/**
 根据索引选中某个item

 @param index 索引
 @param animated 是否使用动画
 */
- (void)selectItemAtIndex:(NSInteger)index animated:(BOOL)animated;

/**
 根据索引和百分比选择一个vc

 @param index 索引
 @param percent 百分比
 */
- (void)selectItemAtIndex:(NSInteger)index withPercent:(CGFloat)percent;

/**
 开始Item的布局，需调用此方法，才会计算item的布局
 */
- (void)layoutItems;

@end
